#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	int n = 0;
	int m = 0;
	cin >> n >> m;
	vector<int> dp(m + 1, m);
	dp[n] = 0;
	for (int i = n; i <= m; ++i)
	{
		for (int j = 2; j * j <= i; ++j)
		{
			if (i % j == 0)
			{
				if (i + j <= m)
					dp[i + j] = min(dp[i + j], dp[i] + 1);
				if (i + i / j <= m)
					dp[i + i / j] = min(dp[i + i / j], dp[i] + 1);
			}
		}
	}
	if (dp[m] == m)
		cout << -1 << endl;
	else
		cout << dp[m] << endl;

	return 0;
}